;;; basic-configs.el - basic configs for emacs.
;;;  
;;; Copyright (C) 2011 Jeffy
;;;  
;;; Author: Jeffy Du (cmdxiaoha@163.com)
;;; Create: 2011-12-23 23:29:57
;;; Last Modified: 2011-12-23 23:44:49
;;;  
;;; History:
;;; --------
;;; 2011-12-23  v0.1  Jeffy Du (cmdxiaoha@163.com)
;;;     1. Initial revision.

;; Personal infomation.
(setq user-full-name    "Jeffy Du")
(setq user-mail-address "cmdxiaoha@163.com")
(setq user-company-name "SIC Microelectronics CO. Ltd")

;; Customize startup.
(setq inhibit-startup-message t)
(setq initial-scratch-message "")

;; Set frame face.
(setq frame-title-format "Emacs - %b")
(setq initial-frame-alist '((width . 110) (height . 35)))
(customize-set-variable 'menu-bar-mode 'nil)
(customize-set-variable 'tool-bar-mode 'nil)
(customize-set-variable 'scroll-bar-mode 'nil)
(setq-default indicate-buffer-boundaries 'right)
(setq column-number-mode t)
(setq echo-keystrokes 0.1)

;; Set mouse.
(mouse-wheel-mode t)
(xterm-mouse-mode t)
(define-key global-map [mouse-4] (lambda() (interactive) (scroll-down 3)))
(define-key global-map [mouse-5] (lambda() (interactive) (scroll-up 3)))

;; Display current function.
(which-func-mode t)
(setq which-func-unknown "unknown")

;; Highlight matched parentheses.
(show-paren-mode t)
(setq show-paren-style 'parentheses)

;; Scroll off beyond the screen edge.
(setq scroll-margin 3)
(setq scroll-conservatively 10000)

;; Basic editing.
(setq-default default-directory "~")
(setq default-major-mode 'text-mode)
(setq-default kill-whole-line t)
(setq enable-recursive-minibuffers t)
(setq make-backup-files nil)
(setq default-truncate-lines t)
(auto-fill-mode t)
(setq auto-raise-mode t)
(setq auto-revert-mode t)
(setq-default indent-tabs-mode t)
(setq default-tab-width 4)
(setq require-final-newline nil)
(add-hook 'find-file-hooks '(lambda () (setq require-final-newline nil)))
(dolist (hook (list
               'emacs-lisp-mode-hook
               'lisp-mode-hook
               'lisp-interaction-mode-hook
               'scheme-mode-hook
               'c-mode-hook
               'c++-mode-hook
               'java-mode-hook
               'haskell-mode-hook
               'asm-mode-hook
               'emms-tag-editor-mode-hook
               'sh-mode-hook
               ))
  (add-hook hook '(lambda () (setq indent-tabs-mode nil))))

;; Don't yank when mouse click middle-butten.
(setq mouse-yank-at-point t)

;; Enable X clipboard.
(setq x-select-enable-clipboard t)

;; Don't save duplicates kill.
(setq kill-do-not-save-duplicates t)

;; Setting minibuffer.
(setq history-delete-duplicates t)
(setq minibuffer-message-timeout 1)

;; Use a large kill ring.
(setq kill-ring-max 200)

;; There is no any ring bell.
(setq ring-bell-function 'ignore)

;; Save last exit place.
(require 'saveplace)
(setq-default save-place t)
(setq save-place-limit 100)
(setq save-place-file "~/.emacs.d/places-list")

;; Time stamp settings.
(setq time-stamp-start "Last Modified: ")
(setq time-stamp-end "\n")
(setq time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S")
(add-hook 'write-file-hooks 'time-stamp)

;; Use y/n to instead yes/no.
(fset 'yes-or-no-p 'y-or-n-p)

;; Enable some usefull functions.
(put 'scroll-left 'disabled nil)
(put 'scroll-right 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'dired-find-alternate-file 'disabled nil)

;; Use ido mode for open file.
(ido-mode t)
(customize-set-variable 'ido-save-directory-list-file
                        (convert-standard-filename "~/.emacs.d/ido-last"))

;; Complete for commands.
(icomplete-mode t)

;; Highlight mark.
(transient-mark-mode t)

;; Use CUA selection mode for select rectangle.
(cua-selection-mode t)

;;Hippie expand function list.
(setq hippie-expand-try-functions-list
      '(try-expand-dabbrev
        try-expand-dabbrev-visible
        try-expand-dabbrev-all-buffers
        try-expand-dabbrev-from-kill
        try-expand-list
        try-expand-list-all-buffers
        try-expand-line
        try-expand-line-all-buffers
        try-complete-file-name-partially
        try-complete-file-name
        try-complete-lisp-symbol-partially
        try-complete-lisp-symbol
        try-expand-whole-line))

;; Enable hs-minor-mode.
(dolist (hook (list
               'emacs-lisp-mode-hook
               'lisp-mode-hook
               'lisp-interaction-mode-hook
               'scheme-mode-hook
               'c-mode-hook
               'c++-mode-hook
               'java-mode-hook
               'haskell-mode-hook
               'asm-mode-hook
               'emms-tag-editor-mode-hook
               'sh-mode-hook
               ))
  (add-hook hook '(lambda () (hs-minor-mode t))))

;; Setting coding system.
(setq default-buffer-file-coding-system 'utf-8-unix)
(setq default-file-name-coding-system 'utf-8-unix)
(setq default-keyboard-coding-system 'utf-8-unix)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
(setq default-sendmail-coding-system 'utf-8-unix)
(setq default-terminal-coding-system 'utf-8-unix)

;; Auto indent after yank.
(defadvice yank (after indent-region activate)
  "To make yank content indent automatically."
  (if (member major-mode '(emacs-lisp-mode
                           scheme-mode
                           lisp-mode
                           lisp-interaction-mode
                           c-mode
                           c++-mode
                           objc-mode
                           latex-mode
                           plain-tex-mode
                           sh-mode))
      (indent-region (region-beginning) (region-end) nil)))

;; Open recent file.
(recentf-mode t)
(setq recentf-max-saved-items 100)
(setq recentf-auto-cleanup 300)
(customize-set-variable 'recentf-save-file
                        (convert-standard-filename "~/.emacs.d/recentf-list"))

;; eshell directorys.
(customize-set-variable 'eshell-directory-name
                        (convert-standard-filename "~/.emacs.d/eshell"))

;; Rename duplicate buffer name.
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
(setq uniquify-separator "/")
(setq uniquify-after-kill-buffer-p t)

;; Delete the end blanks.
(setq whitespace-global-mode t)